<template>
  <p-dialog :visible="visible" @close="$emit('close')">

    <el-alert
      title="激活文件提示"
      type="success"
      description="请将获取到的base64编码复制到项目中的离线激活输入框中进行激活"
      :closable="false"
      show-icon>
    </el-alert>

    <el-input
      v-loading="loading"
      type="textarea"
      style="margin-top:10px;"
      :rows="6"
      :editable="false"
      ref="input"
      v-model="info">
    </el-input>
    <div class="text-right">
      <el-button type="primary" style="margin-top:10px" size="mini" @click="copy()">复制</el-button>
    </div>
  </p-dialog>
</template>

<script>
import api from "@/utils/api";

export default {
  name: "ActiveDownload",
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    id: {
      type: Number,
      default: null
    }
  },
  watch: {
    id(val) {
      if (val) {
        this.loadData();
      }
    }
  },
  data() {
    return {
      info: '',
      loading: false
    }
  },
  methods: {
    copy() {
      this.$refs.input.select();
      document.execCommand('Copy');
      this.$message.success('复制成功！');
    },
    loadData() {
      let self = this;
      self.loading = true;
      api.orderActiveHistoryDownload(this.id).then(data => {
        self.info = data;
      }).finally(() => self.loading = false);
    }
  }
}
</script>

<style scoped>

</style>
